package com.tuanzi.loan.security;

import java.util.Collection;

import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.web.FilterInvocation;
import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
import org.springframework.stereotype.Component;

import com.google.common.collect.Lists;

@Component
public class LoanInvocationSecurityMetadataSource implements FilterInvocationSecurityMetadataSource {

	public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {

		String url = ((FilterInvocation) object).getRequestUrl();
		if (url.startsWith("/views")) {
			return Lists.newArrayList(new SecurityConfig(LoanSecurityConstants.AUTHENTICATION_KEY));
		}
		return Lists.newArrayList();
	}

	public Collection<ConfigAttribute> getAllConfigAttributes() {
		return Lists.newArrayList(new SecurityConfig(LoanSecurityConstants.AUTHENTICATION_KEY));
	}

	public boolean supports(Class<?> clazz) {
		return true;
	}

}
